﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" Inherits="Users_Reg" Title="Untitled Page" Codebehind="Reg.aspx.cs" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script type="text/javascript" src="../Include/JS/Lib/jquery-1.1.4.js"></script>
<script type="text/javascript" src="../Include/JS/Products/Address.js"></script>
<script type="text/javascript" src="../Include/JS/qq.js"></script>
<script type="text/javascript">
var  $j = jQuery.noConflict();

function Clear(obj)
{
    if(obj.value=="区号"||obj.value=="号码"||obj.value=="分机")
    {
        obj.value="";
    }
}
function RegAddress_Init()
{  
     $j.post("../Handler/AddressHandler.ashx", {OP:"RegAddress"},
            function(data){                          
               eval(data);
               InitProvince();
            }
        );
}
function GetRegAreaList(value,selectvalue)
{
    LoadArea=false;
    if(parseInt(value)>-1)
    {
        $j.post("../Handler/AddressHandler.ashx", {City:value, OP:"Area"},
                function(data){                          
                   InitArea(data,selectvalue);
                }
            );
     }
     else
     {
        var sel = document.getElementById("Area"); 
    
        while( sel.length>0 )
        {
            sel.removeChild(sel.options(0));
            
        }
        sel.options[0]=new Option("请选择","-1");
     }
}
function Check()
{
    var UserCode=document.getElementById("txtAccounts");
    var userName = document.getElementById("txtUserName");
    var province = document.getElementById("Province");
    var city =  document.getElementById("City");
    var area = document.getElementById("Area");
    var address = document.getElementById("txtAddress");
    var postCode = document.getElementById("txtPostCode");
    var mobile = document.getElementById("txtMobile");
    var phone = document.getElementById("txtPhone");//区号
    var phone1=document.getElementById("txtPhone2");//电话号码
    var phone2=document.getElementById("txtPhone3");//分机号码
    if(UserCode.value.length<1)
    {
        alert("昵称不能为空");
        UserCode.focus();
        return false;
    }
    if(UserCode.value.length>50)
    {
        alert("昵称长度不能超过50位");
        UserCode.focus();
        return false;
    }
    /*var pattern = /[^0-9.@a-zA-Z]/g;
    if(pattern.test(UserCode.value))
    {
        alert("昵称只能输入数据或字母");
        UserCode.focus();
        return false;
    }*/
    if(province.selectedIndex<1)
    {
        alert("请选择省份");
        province.focus();
        return false;
    }
    if(city.selectedIndex<1)
    {
        alert("请选择城市");
        city.focus();
        return false;
    }
    if(area.selectedIndex<1)
    {
        alert("请选择区县");
        area.focus();
        return false;
    }
    /*Ltl's code begin*/
    if(address.value.length<1)
    {
        alert("详细地址不能为空");
        address.focus();
        return false;
    }
    //var pattern = /^[1-9][0-9]{5}$/;
    //if(pattern.test(postCode.value))
    if(postCode.value.length<1)
    {
        alert("邮编不能为空");
        postCode.focus();
        return false;
    }
    
    if(isNaN(postCode.value))
    {
        alert("邮编格式错误,请检查您输入法的全角/半角状态！");
        postCode.focus();
        return false;
    }
    var regular=/^\d{6}$/;
    if(!regular.test(postCode.value))
    {
        alert("邮编不正确");
        postCode.focus();
        return false;
    }
    
    if((phone1.value.length==0||phone1.value=="号码")&&mobile.value.length==0)
    {alert("手机或固定电话必填一个"); return false;}
    debugger;
    if(phone.value.length>0&&phone.value!="区号"||phone1.value.length>0&&phone1.value!="号码"||phone2.value.length>0&&phone2.value!="分机")
    {
        if((phone.value.length>0&&phone.value!="区号")||(phone1.value.length>0&&phone1.value!="号码"))
        {
            if(isNaN(phone.value)||isNaN(phone1.value))
            {
                alert("固定电话格式错误,请检查您输入法的全角/半角状态！");
                return false;
            }
            var reg=/^\d{3,4}$/;//检查区号

            var reg1=/^\d{7,8}$/;//检查电话号码

            if(!reg.test(phone.value)||!reg1.test(phone1.value))
            {
                alert("固定电话格式错误");
                return false;
            }
        }
        if(phone2.value.length>0&&phone2.value!="分机")
        {
            if(isNaN(phone.value)||isNaN(phone1.value)||isNaN(phone2.value))
            {
                alert("固定电话格式错误,请检查您输入法的全角/半角状态！");
                return false;
            }
            var reg=/^\d{3,4}$/;//检查区号

            var reg1=/^\d{7,8}$/;//检查电话号码

            var reg2=/^\d{1,5}$/;//检查分机号
            if(!reg.test(phone.value)||!reg1.test(phone1.value)||!reg2.test(phone2.value))
            {
                alert("固定电话格式错误");
                return false;
            }
        }
    }
    var phone0="";
        if(phone1.value.length>0&&phone1.value!="号码")
        {
            phone0=phone.value+"-"+phone1.value;            
        }
        if(phone2.value.length>0&&phone2.value!="分机")
        {
            phone0=phone.value+"-"+phone1.value+"-"+phone2.value;
        }
    if(mobile.value.length>0)
    {
        if(isNaN(mobile.value))
        {
            alert("手机号码含有非法字符");
            mobile.focus();
            return false;
        }
        var reg=/^\d+$/;//检查手机

        if(!reg.test(mobile.value))
        {
            alert("请输入正确的手机号码");
            mobile.focus();
            return false;
        }
    }
    /*Ltl's code end*/
    var Sex0=document.getElementById("rblSex_0");
    var Sex1=document.getElementById("rblSex_1");
    var sexvalue;
    if(!Sex0.checked&&!Sex1.checked)
    {
        alert("请选择性别");
        return false;
    }
    if(Sex0.checked)
    {
        sexvalue="男";
    }
    if(Sex1.checked)
    {
        sexvalue="女";
    }
    var Password1=document.getElementById("Password1");
    var Password2=document.getElementById("Password2");
    if(Password1.value.length<1)
    {
        alert("密码不能为空");
        Password1.focus();
        return false;
    }
    if(Password2.value.length<1)
    {
        alert("确认密码不能为空");
        Password2.focus();
        return false;
    }
    if(Password1.value!=Password2.value)
    {
        alert("两次输入密码不一致");
        Password1.focus();
        return false;
    }
    var txtEmail=document.getElementById("txtEmail");
    if(txtEmail.value.length>0)
    {
        var pattern = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; 
        var flag = pattern.test(txtEmail.value); 
        if(!flag)
        {
            alert("Email格式不正确!");
            txtEmail.focus();
            return false;
        }
    }
    Mask();
    document.getElementById("ShoppingCart").innerHTML="<br /><br />数据加载中......<br /><br /><img src='../images/ajax-loader.gif'>";
    CallServer(UserCode.value,sexvalue,Password1.value,txtEmail.value,userName.value,province.value,city.value,area.value,address.value,postCode.value,mobile.value,phone0);    
}
function NameTS(value,color)
{
    document.getElementById("Name").innerHTML="<span  style=\"color:"+color+"\">"+value+"</span>";
}
function PWDTS(value,color)
{
    document.getElementById("Pwd").innerHTML="<span  style=\"color:"+color+"\">"+value+"</span>";
}
function Mask()
{ 
    var div_back = document.getElementById("div_background");
    div_back.style.display = "block"; 
    var iframe_back = document.getElementById("iframe_back");
    iframe_back.style.display = "block";  
    var sizeList = document.getElementById("Submit"); 
    sizeList.disabled = true; 
    var cart = document.getElementById("ShoppingCart");
    cart.style.display = "block";
    cart.style.position = "absolute";
    var bigImg = document.getElementById("Rg");
    var pleft = 0;
    var ptop = 0;
   
    var obj = bigImg.offsetParent;
 
    while(obj.tagName != "BODY")
    {
         pleft = pleft + obj.offsetLeft;
         ptop = ptop + obj.offsetTop;
         obj = obj.offsetParent;
    }
    ptop = ptop + 150;
    cart.style.left = pleft +100+ "px";
    cart.style.top = ptop +"px";
    cart.style.width = 300 + "px";
    cart.style.backgroundColor  = "#ffffff";
}
function hide()
{
  var div_back = document.getElementById("div_background");
    div_back.style.display = "none"; 
     var iframe_back = document.getElementById("iframe_back");
    iframe_back.style.display = "none";   
    var sizeList = document.getElementById("Submit"); 
    sizeList.disabled = false;
    var cart = document.getElementById("ShoppingCart");
    cart.style.display = "none";    
}
function CallServer(UserCode,Sex,Pwd,Email,UserName,Province,City,Area,Address,PostCode,Mobile,Phone)  
{ 
      arg = UserCode+"|"+Sex+"|"+Pwd+"|"+Email+"|"+UserName+"|"+Province+"|"+City+"|"+Area+"|"+Address+"|"+PostCode+"|"+Mobile+"|"+Phone;   
      <%= ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "")%>;   
}   
 function ReceiveServerData(result)   
 {  
     switch (result)
     {
        case "-2":
            hide(); 
            alert("信息中有空值")  ;
            break;
        case "-1":
            hide(); 
            alert("网站配置信息有错,请联系管理员");
            break;
        case "0":
            hide();
            alert("注册失败");
            break;
        case "1":
            hide();
            alert("昵称有重复");
            break;
        case "2":
            hide();
            alert("Email有重复");
            break;
        case "3":
            hide();
            alert("用户昵称有重复");
            break;
        default:
            window.location.href="RegSuccess.aspx";
            
     }
     
 } 
 RegAddress_Init();
</script>
    <div class="r_content">
        <div class="r_gouwu">
            <div class="r_gouwu_title">
                <h2>
                    用户注册</h2>
            </div>
            <div class="r_reg" id="Rg">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="100" align="left">
                            昵称：</td>
                        <td width="200">
                            <input id="txtAccounts" name="txtAccounts" class="inputbox" onclick="NameTS('请输入数字或字母,长度不要超过20位','Green')"></td>
                        <td  id="Name" align="left"><font color="red">*</font>
                            </td>
                    </tr>
                    <tr>
                        <td align="left" style="height: 20px">
                            性别：</td>
                        <td style="height: 20px">
                            <input id="rblSex_0" type="radio" checked value="男" name="rblSex"/>
                            <label for="rblSex_0">
                                男</label><input id="rblSex_1" type="radio" value="女" name="rblSex"/>
                            <label for="rblSex_1">
                                女</label></td>
                        <td style="height: 20px" align="left">
                            <font color="red">*</font></td>
                    </tr>
                    <tr>
                        <td align="left" style="height: 26px">
                            用户密码：</td>
                        <td style="height: 26px">
                            <input id="Password1" type="password" name="Password1" class="inputbox" onclick="PWDTS('密码区分大小写','Green')" style="width: 148px"></td>
                        <td  id="Pwd" style="height: 26px"><font color="red">*</font>
                           </td>
                    </tr>
                    <tr>
                        <td align="left" style="height: 26px">
                            密码确认：</td>
                        <td style="height: 26px">
                            <input id="Password2" type="password" name="Password2" class="inputbox" style="width: 149px"></td>
                        <td style="height: 26px" align="left">
                            <font color="red">*</font></td>
                    </tr>
                    <tr>
                        <td align="left" style="height: 24px">
                            Email：</td>
                        <td style="height: 24px">
                            <input id="txtEmail" name="txtEmail" class="inputbox" style="width: 189px"></td>
                        <td style="height: 24px" align="left">
                            </td>
                    </tr>
                    
                    <tr height="10">
                        <td style="height: 10px">
                            用户真实姓名：

                        </td>
                        <td style="height: 10px">
                            <input id="txtUserName" type="text" />
                        </td>
                        <td style="height: 10px" align="left"><font color="red">*</font></td>
                    </tr>
                    <tr>
                        <td  align="left" style="height: 26px">
                            地址：</td>
                        <td align="left">
                            <div style="float: left;">
                                <select id="Province" onchange="GetCityList(this.value)">
                                    <option></option>
                                </select>
                                <select id="City" onchange="GetRegAreaList(this.value)">
                                    <option>请选择</option>
                                </select>
                                <select id="Area">
                                    <option>请选择</option>
                                </select>
                            </div>
                        </td>
                            <td style="height: 10px" align="left"><font color="red">*</font></td>
                    </tr>                    
                    <tr height="10">
                        <td style="height: 10px">
                            详细地址：

                        </td>
                    <td style="height: 10px">
                        <input id="txtAddress" type="text" />
                    </td>
                    <td style="height: 10px" align="left"><font color="red">*</font></td>
                    </tr>
                    
                    <tr height="10">
                        <td style="height: 10px">
                            邮编：

                        </td>
                    <td style="height: 10px">
                        <input id="txtPostCode" type="text" />
                    </td>
                    <td style="height: 10px" align="left"><font color="red">*</font></td>
                    </tr>
                    
                    <tr height="10">
                        <td style="height: 10px">
                            手机：

                        </td>
                        <td style="height: 10px">
                            <input id="txtMobile" type="text" />
                        </td>
                        <td style="height: 10px" align="left"><font color="red">*</font></td>
                    </tr>
                    <tr height="10">
                        <td style="height: 10px">
                            固定电话：

                        </td>
                        <td style="height: 10px">
                        <input class="inputbox" id="txtPhone" type="text" size="5" name="txtNewPwd1" value="区号" onfocus="Clear(this)" />
                        <input class="inputbox" id="txtPhone2" type="text" size="14" name="txtNewPwd2" value="号码" onfocus="Clear(this)" />
                        <input class="inputbox" id="txtPhone3" type="text" size="14" name="txtNewPwd3" value="分机" onfocus="Clear(this)" />
                        </td>
                        <td style="height: 10px" align="left"><font color="red">*</font></td>
                    </tr>
                    
                    <tr>
                        <td>
                            &nbsp;</td>
                        <td>
                            <div class="r_reg_bt">
                                <a href="javascript:" onclick="Check()" id="Submit">提交注册</a></div>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="clear">
            </div>
        </div>
    </div>
    <div id="div_background" class="divbackground" onclick="hide();">
    </div>
    <iframe id="iframe_back" class="diviframe" frameborder="0"></iframe>
    <div id="ShoppingCart" style="z-index: 11; display: none">
    </div>
    <!-- content -->
</asp:Content>
